<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>开发封装函数 | 孙志豪的博客</title><meta name="author" content="孙志豪"><meta name="copyright" content="孙志豪"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="开发封装函数创建项目封装axios 创建一个文件夹  utils  &gt; request.js   把代码扔进去  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667&#x2F;&#x2F;  npm i axio">
<meta property="og:type" content="article">
<meta property="og:title" content="开发封装函数">
<meta property="og:url" content="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/index.html">
<meta property="og:site_name" content="孙志豪的博客">
<meta property="og:description" content="开发封装函数创建项目封装axios 创建一个文件夹  utils  &gt; request.js   把代码扔进去  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667&#x2F;&#x2F;  npm i axio">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg">
<meta property="article:published_time" content="2022-10-11T12:01:36.000Z">
<meta property="article:modified_time" content="2022-10-11T09:13:18.576Z">
<meta property="article:author" content="孙志豪">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"We didn't find any results for the search: ${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '开发封装函数',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-10-11 17:13:18'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/%E5%A4%A9%E7%A9%BA.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">孙志豪的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> Search</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">开发封装函数</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-10-11T09:13:18.576Z" title="Updated 2022-10-11 17:13:18">2022-10-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/">核心js（手写篇）</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="开发封装函数"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><hr>
<h1 id="开发封装函数"><a href="#开发封装函数" class="headerlink" title="开发封装函数"></a>开发封装函数</h1><h3 id="创建项目封装axios"><a href="#创建项目封装axios" class="headerlink" title="创建项目封装axios"></a>创建项目封装axios</h3><blockquote>
<p>创建一个文件夹  utils  &gt; request.js   把代码扔进去</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  npm i axios</span></span><br><span class="line"><span class="comment">// 1. 创建一个新的axios实例</span></span><br><span class="line"><span class="comment">// 2. 请求拦截器，如果有token进行头部携带</span></span><br><span class="line"><span class="comment">// 3. 响应拦截器：1. 剥离无效数据  2. 处理token失效</span></span><br><span class="line"><span class="comment">// 4. 导出一个函数，调用当前的axsio实例发请求，返回值promise</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">&#x27;axios&#x27;</span></span><br><span class="line"><span class="keyword">import</span> store <span class="keyword">from</span> <span class="string">&#x27;@/store&#x27;</span></span><br><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">&#x27;@/router&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 导出基准地址，原因：其他地方不是通过axios发请求的地方用上基准地址</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> baseURL = <span class="string">&#x27;http://pcapi-xiaotuxian-front-devtest.itheima.net/&#x27;</span></span><br><span class="line"><span class="keyword">const</span> instance = axios.<span class="title function_">create</span>(&#123;</span><br><span class="line">  <span class="comment">// axios 的一些配置，baseURL  timeout</span></span><br><span class="line">  baseURL,</span><br><span class="line">  <span class="attr">timeout</span>: <span class="number">5000</span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">instance.<span class="property">interceptors</span>.<span class="property">request</span>.<span class="title function_">use</span>(<span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 拦截业务逻辑</span></span><br><span class="line">  <span class="comment">// 进行请求配置的修改</span></span><br><span class="line">  <span class="comment">// 如果本地又token就在头部携带</span></span><br><span class="line">  <span class="comment">// 1. 获取用户信息对象</span></span><br><span class="line">  <span class="keyword">const</span> &#123; profile &#125; = store.<span class="property">state</span>.<span class="property">user</span></span><br><span class="line">  <span class="comment">// 2. 判断是否有token</span></span><br><span class="line">  <span class="keyword">if</span> (profile.<span class="property">token</span>) &#123;</span><br><span class="line">    <span class="comment">// 3. 设置token</span></span><br><span class="line">    config.<span class="property">headers</span>.<span class="property">Authorization</span> = <span class="string">`Bearer <span class="subst">$&#123;profile.token&#125;</span>`</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> config</span><br><span class="line">&#125;, <span class="function"><span class="params">err</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title class_">Promise</span>.<span class="title function_">reject</span>(err)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// res =&gt; res.data  取出data数据，将来调用接口的时候直接拿到的就是后台的数据</span></span><br><span class="line">instance.<span class="property">interceptors</span>.<span class="property">response</span>.<span class="title function_">use</span>(<span class="function"><span class="params">res</span> =&gt;</span> res.<span class="property">data</span>, <span class="function"><span class="params">err</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 401 状态码，进入该函数</span></span><br><span class="line">  <span class="keyword">if</span> (err.<span class="property">response</span> &amp;&amp; err.<span class="property">response</span>.<span class="property">status</span> === <span class="number">401</span>) &#123;</span><br><span class="line">    <span class="comment">// 1. 清空无效用户信息</span></span><br><span class="line">    <span class="comment">// 2. 跳转到登录页</span></span><br><span class="line">    <span class="comment">// 3. 跳转需要传参（当前路由地址）给登录页码</span></span><br><span class="line">    store.<span class="title function_">commit</span>(<span class="string">&#x27;user/setUser&#x27;</span>, &#123;&#125;)</span><br><span class="line">    <span class="comment">// 当前路由地址</span></span><br><span class="line">    <span class="comment">// 组件里头：`/user?a=10` $route.path === /user  $route.fullPath === /user?a=10</span></span><br><span class="line">    <span class="comment">// js模块中：router.currentRoute.value.fullPath 就是当前路由地址，router.currentRoute 是ref响应式数据</span></span><br><span class="line">    <span class="keyword">const</span> fullPath = <span class="built_in">encodeURIComponent</span>(router.<span class="property">currentRoute</span>.<span class="property">value</span>.<span class="property">fullPath</span>)</span><br><span class="line">    <span class="comment">// encodeURIComponent 转换uri编码，防止解析地址出问题</span></span><br><span class="line">    router.<span class="title function_">push</span>(<span class="string">&#x27;/login?redirectUrl=&#x27;</span> + fullPath)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="title class_">Promise</span>.<span class="title function_">reject</span>(err)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 请求工具函数</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> (url, method, submitData) =&gt; &#123;</span><br><span class="line">  <span class="comment">// 负责发请求：请求地址，请求方式，提交的数据</span></span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">instance</span>(&#123;</span><br><span class="line">    url,</span><br><span class="line">    method,</span><br><span class="line">    <span class="comment">// 1. 如果是get请求  需要使用params来传递submitData   ?a=10&amp;c=10</span></span><br><span class="line">    <span class="comment">// 2. 如果不是get请求  需要使用data来传递submitData   请求体传参</span></span><br><span class="line">    <span class="comment">// [] 设置一个动态的key, 写js表达式，js表达式的执行结果当作KEY</span></span><br><span class="line">    <span class="comment">// method参数：get,Get,GET  转换成小写再来判断</span></span><br><span class="line">    <span class="comment">// 在对象，[&#x27;params&#x27;]:submitData ===== params:submitData 这样理解</span></span><br><span class="line">    [method.<span class="title function_">toLowerCase</span>() === <span class="string">&#x27;get&#x27;</span> ? <span class="string">&#x27;params&#x27;</span> : <span class="string">&#x27;data&#x27;</span>]: submitData</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>创建 api 文件夹 index.js</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 举一些例子</span></span><br><span class="line"><span class="comment">// 定义首页需要的接口函数</span></span><br><span class="line"><span class="keyword">import</span> request <span class="keyword">from</span> <span class="string">&#x27;@/utils/request&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取首页头部分类数据</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> <span class="title function_">findAllCategory</span> = (<span class="params"></span>) =&gt; &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">request</span>(<span class="string">&#x27;/home/category/head&#x27;</span>, <span class="string">&#x27;get&#x27;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取热榜商品</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> &#123;<span class="type">Number</span>&#125; <span class="variable">type</span> - 1代表24小时热销榜 2代表周热销榜 3代表总热销榜</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> &#123;<span class="type">Number</span>&#125; <span class="variable">limit</span> - 获取个数</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> <span class="title function_">findHotGoods</span> = (<span class="params">&#123;id,type, limit = <span class="number">3</span>&#125;</span>) =&gt; &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">request</span>(<span class="string">&#x27;/goods/hot&#x27;</span>, <span class="string">&#x27;get&#x27;</span>, &#123;id, type, limit &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="中间字符变成-星号"><a href="#中间字符变成-星号" class="headerlink" title="中间字符变成 星号"></a>中间字符变成 星号</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">formatNickname</span> = (<span class="params">nickname</span>) =&gt; &#123;</span><br><span class="line">    <span class="comment">// 把第一字符和最后一个字符取出然后拼接</span></span><br><span class="line">    <span class="keyword">return</span> nickname.<span class="title function_">substr</span>(<span class="number">0</span>, <span class="number">1</span>) + <span class="string">&#x27;****&#x27;</span> + nickname.<span class="title function_">substr</span>(-<span class="number">1</span>)</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h3 id="reduce-过滤转换格式"><a href="#reduce-过滤转换格式" class="headerlink" title="reduce 过滤转换格式"></a>reduce 过滤转换格式</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">formatSpecs</span> = (<span class="params">specs</span>) =&gt; &#123;</span><br><span class="line">  <span class="keyword">return</span> specs.<span class="title function_">reduce</span>(<span class="function">(<span class="params">p, c</span>) =&gt;</span> <span class="string">`<span class="subst">$&#123;p&#125;</span> <span class="subst">$&#123;c.name&#125;</span>：<span class="subst">$&#123;c.nameValue&#125;</span>`</span>, <span class="string">&#x27;&#x27;</span>).<span class="title function_">trim</span>()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="购物车的算法逻辑"><a href="#购物车的算法逻辑" class="headerlink" title="购物车的算法逻辑"></a>购物车的算法逻辑</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"> <span class="attr">watch</span>: &#123; <span class="comment">// 计算购物车</span></span><br><span class="line">   <span class="attr">objList</span>: &#123;</span><br><span class="line">     <span class="attr">deep</span>: <span class="literal">true</span>,</span><br><span class="line">     <span class="title function_">handler</span>(<span class="params">value</span>) &#123;</span><br><span class="line">     <span class="comment">// 小计</span></span><br><span class="line">       <span class="variable language_">this</span>.<span class="property">num</span> = value.<span class="title function_">reduce</span>(</span><br><span class="line">         <span class="function">(<span class="params">num, value</span>) =&gt;</span> (num += value.<span class="property">ischeck</span> &amp;&amp; value.<span class="property">num</span> * value.<span class="property">price</span>),</span><br><span class="line">         <span class="number">0</span></span><br><span class="line">       );</span><br><span class="line">     <span class="comment">// 总数</span></span><br><span class="line">       <span class="variable language_">this</span>.<span class="property">subtotal</span> = value.<span class="title function_">reduce</span>(</span><br><span class="line">         <span class="function">(<span class="params">num, value</span>) =&gt;</span> (num += value.<span class="property">num</span> &amp;&amp; value.<span class="property">ischeck</span>),</span><br><span class="line">         <span class="number">0</span></span><br><span class="line">       );</span><br><span class="line">     &#125;,</span><br><span class="line">   &#125;,</span><br><span class="line"> &#125;,</span><br><span class="line"> </span><br><span class="line"> <span class="comment">/*</span></span><br><span class="line"><span class="comment"> *  算出为 true 的长度</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="title function_">reduce</span>(<span class="function">(<span class="params">pre, current</span>) =&gt;</span> pre + (current.<span class="property">dond</span> ? <span class="number">1</span> : <span class="number">0</span>), <span class="number">0</span>); <span class="comment">// 直接拿到为true 的长度</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="title function_">filter</span>(<span class="function"><span class="params">item</span> =&gt;</span> item.<span class="property">dond</span> == <span class="literal">true</span>).<span class="property">length</span>  <span class="comment">// 直接拿到为true 的长度</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (!event.<span class="property">target</span>.<span class="property">value</span>.<span class="title function_">trim</span>()) <span class="keyword">return</span> <span class="title function_">alert</span>(<span class="string">&quot;输入不能为空&quot;</span>); <span class="comment">// 输入不能为空</span></span><br><span class="line"> </span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="title function_">forEach</span>(<span class="function">(<span class="params">element</span>) =&gt;</span> &#123;   <span class="comment">// 操作 反选 让他 为true 或者 为 false</span></span><br><span class="line">       <span class="keyword">if</span> (element.<span class="property">id</span> == item) element.<span class="property">dond</span> = !element.<span class="property">dond</span>;</span><br><span class="line"> &#125;);</span><br><span class="line"> </span><br><span class="line"> <span class="title function_">removeCheckbox</span>(<span class="params">state, value</span>) &#123; <span class="comment">//删除选中的复选框</span></span><br><span class="line">     state.<span class="property">addsHOPPING</span> = state.<span class="property">addsHOPPING</span>.<span class="title function_">filter</span>(<span class="function"><span class="params">item</span> =&gt;</span> value.<span class="title function_">includes</span>(item) == <span class="string">&quot;&quot;</span>)</span><br><span class="line">     <span class="comment">// 传过来的数据检查 原有的数据 检查到的数据给他= “” 或者是false </span></span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"> vue3</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> shopNum = <span class="title function_">reactive</span>(&#123;</span><br><span class="line">     <span class="attr">nn</span>: <span class="title function_">computed</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">       <span class="keyword">let</span> nums = <span class="number">0</span>;</span><br><span class="line">       obj.<span class="property">value</span>.<span class="title function_">forEach</span>(<span class="function">(<span class="params">item</span>) =&gt;</span> &#123;</span><br><span class="line">         <span class="keyword">if</span> (item.<span class="property">checked</span>) &#123;</span><br><span class="line">           nums += item.<span class="property">num</span>;</span><br><span class="line">         &#125;</span><br><span class="line">       &#125;);</span><br><span class="line">       <span class="keyword">return</span> nums;</span><br><span class="line">     &#125;),</span><br><span class="line">   &#125;);</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"> </span><br></pre></td></tr></table></figure>

<h3 id="商品卡片加入购物车判断重复"><a href="#商品卡片加入购物车判断重复" class="headerlink" title="商品卡片加入购物车判断重复"></a>商品卡片加入购物车判断重复</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1.方案</span></span><br><span class="line">state.<span class="property">addsHOPPING</span>.<span class="title function_">forEach</span>(<span class="function"><span class="params">item</span> =&gt;</span> &#123; 添加商品卡片</span><br><span class="line">        <span class="keyword">if</span> (item.<span class="property">_id</span> == value.<span class="property">_id</span>) &#123; <span class="comment">// 重复的代码 执行</span></span><br><span class="line">          flag = <span class="literal">true</span> <span class="comment">//  没有重复就会执行下面代码添加一个 有重复有 flag = true 下面就不会执行了 有重复的就不让添加了</span></span><br><span class="line">          <span class="comment">// console.log(item.num);</span></span><br><span class="line">          <span class="comment">// item.num + state.addNum</span></span><br><span class="line">          item.<span class="property">num</span>++</span><br><span class="line">        &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">   <span class="keyword">if</span> (flag == <span class="literal">false</span>) &#123; <span class="comment">// flag ==false 才会执行 若果有重复就会变成true不让执行了 若果没有重复的 就执行这个</span></span><br><span class="line">        value.<span class="property">num</span> = <span class="number">1</span></span><br><span class="line">        state.<span class="property">addsHOPPING</span>.<span class="title function_">unshift</span>(value)</span><br><span class="line">   &#125; </span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">   <span class="comment">//  2.方案</span></span><br><span class="line">   <span class="keyword">let</span> index = state.<span class="property">objList</span>.<span class="title function_">findIndex</span>(<span class="function"><span class="params">item</span> =&gt;</span> item.<span class="property">cid</span> == value.<span class="property">cid</span>)   <span class="comment">//  判重 findindex添加商品卡片</span></span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(index);<span class="comment">// 重复的代码 执行</span></span><br><span class="line">      <span class="keyword">if</span> (index != -<span class="number">1</span>) &#123;</span><br><span class="line">        state.<span class="property">objList</span>[index].<span class="property">num</span>++</span><br><span class="line">      &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        state.<span class="property">objList</span>.<span class="title function_">push</span>(value)</span><br><span class="line">    &#125;</span><br><span class="line">   </span><br><span class="line">  <span class="comment">// 历史记录</span></span><br><span class="line">      <span class="keyword">let</span> flag = state.<span class="property">objList</span>.<span class="title function_">findIndex</span>(<span class="function"><span class="params">item</span> =&gt;</span> item == value)</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(flag);</span><br><span class="line">      <span class="keyword">if</span> (flag &gt; -<span class="number">1</span>) &#123;</span><br><span class="line">        state.<span class="property">objList</span>.<span class="title function_">splice</span>(flag, <span class="number">1</span>)</span><br><span class="line">      &#125;</span><br><span class="line">      state.<span class="property">objList</span>.<span class="title function_">unshift</span>(value)</span><br></pre></td></tr></table></figure>

<h3 id="全选反选"><a href="#全选反选" class="headerlink" title="全选反选"></a>全选反选</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">this</span>.<span class="property">obj</span> = <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="title function_">filter</span>(<span class="function">(<span class="params">elment</span>) =&gt;</span> &#123;  <span class="comment">// 删除一条数据</span></span><br><span class="line">      <span class="keyword">return</span> elment.<span class="property">id</span> !== item;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> flag = obj.<span class="property">value</span>.<span class="title function_">every</span>(<span class="function">(<span class="params">item</span>) =&gt;</span> &#123;</span><br><span class="line">         <span class="keyword">return</span> item.<span class="property">checked</span>;</span><br><span class="line">       &#125;);</span><br><span class="line">       <span class="keyword">if</span> (flag &amp;&amp; obj.<span class="property">value</span>.<span class="property">length</span> != <span class="number">0</span>) &#123;</span><br><span class="line">         <span class="comment">// 假设有长度 肯定要 true</span></span><br><span class="line">         checkAllChange.<span class="property">value</span> = <span class="literal">true</span>;</span><br><span class="line">       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">         checkAllChange.<span class="property">value</span> = <span class="literal">false</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       </span><br><span class="line"></span><br><span class="line"><span class="variable language_">this</span>.<span class="property">obj</span>.<span class="title function_">forEach</span>(<span class="function">(<span class="params">element</span>) =&gt;</span> &#123;  <span class="comment">// 复选框反选</span></span><br><span class="line">       element.<span class="property">dond</span> = !element.<span class="property">dond</span>;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">trueLEngtn</span> == <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="property">length</span> &amp;&amp; <span class="variable language_">this</span>.<span class="property">obj</span>.<span class="property">length</span> &gt; <span class="number">0</span>;<span class="comment">// 复选框反选完美写法</span></span><br></pre></td></tr></table></figure>

<h3 id="商品选规格样式的逻辑"><a href="#商品选规格样式的逻辑" class="headerlink" title="商品选规格样式的逻辑"></a>商品选规格样式的逻辑</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"> &lt;template&gt;</span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;goods-sku&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;<span class="name">dl</span> <span class="attr">v-for</span>=<span class="string">&quot;(v, i) in obj.specs&quot;</span> <span class="attr">:key</span>=<span class="string">&quot;i&quot;</span>&gt;</span> // 父数据 </span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">dt</span>&gt;</span>&#123;&#123; v.name &#125;&#125;<span class="tag">&lt;/<span class="name">dt</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">dd</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">template</span> <span class="attr">v-for</span>=<span class="string">&quot;(item, ii) in v.values&quot;</span> <span class="attr">:key</span>=<span class="string">&quot;ii&quot;</span>&gt;</span>      </span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;<span class="name">span</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">            @<span class="attr">click</span>=<span class="string">&quot;changeFlag(v, item)&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">            <span class="attr">:class</span>=<span class="string">&quot;&#123; selected: item.selected&#125;&quot;</span> // 子数据给它加上样式</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">            &gt;</span>&#123;&#123; item.name &#125;&#125;&lt;/span</span></span><br><span class="line"><span class="language-xml">          &gt;</span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;/<span class="name">template</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;/<span class="name">dd</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">dl</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// 规格商品的 class 类激活   v 是父数据  item是子数据</span></span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">changeFlag</span>(<span class="params">v, item</span>) &#123;</span><br><span class="line">      <span class="keyword">if</span> (item.<span class="property">selected</span>) &#123;</span><br><span class="line">        <span class="comment">// 循环子元素的每一个给它添加一个 selected 属性并且默认是 false</span></span><br><span class="line">        item.<span class="property">selected</span> = <span class="literal">false</span>;</span><br><span class="line">      &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 循环父数据里面子数据的 selected 给他变为false</span></span><br><span class="line">        v.<span class="property">values</span>.<span class="title function_">forEach</span>(<span class="function">(<span class="params">item</span>) =&gt;</span> &#123;</span><br><span class="line">          item.<span class="property">selected</span> = <span class="literal">false</span>;</span><br><span class="line">        &#125;);</span><br><span class="line">        <span class="comment">// 如果为false 就等于 true</span></span><br><span class="line">        item.<span class="property">selected</span> = <span class="literal">true</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="数据的一个懒加载"><a href="#数据的一个懒加载" class="headerlink" title="数据的一个懒加载"></a>数据的一个懒加载</h3><blockquote>
<p>建一个 hooks 文件 &gt; index.js 放入下面内容</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  cnpm install --save @vueuse/core  </span></span><br><span class="line"><span class="comment">// hooks 封装逻辑，提供响应式数据。 下载依赖</span></span><br><span class="line"><span class="keyword">import</span> &#123;</span><br><span class="line">  useIntersectionObserver</span><br><span class="line">&#125; <span class="keyword">from</span> <span class="string">&#x27;@vueuse/core&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123;</span><br><span class="line">  ref</span><br><span class="line">&#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="comment">// 数据懒加载函数</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> <span class="title function_">useLazyData</span> = (<span class="params">apiFn</span>) =&gt; &#123;</span><br><span class="line">  <span class="comment">// 需要</span></span><br><span class="line">  <span class="comment">// 1. 被观察的对象</span></span><br><span class="line">  <span class="comment">// 2. 不同的API函数</span></span><br><span class="line">  <span class="keyword">const</span> result = <span class="title function_">ref</span>([])</span><br><span class="line">  <span class="keyword">const</span> target = <span class="title function_">ref</span>(<span class="literal">null</span>)</span><br><span class="line">  <span class="keyword">const</span> &#123;</span><br><span class="line">    stop</span><br><span class="line">  &#125; = <span class="title function_">useIntersectionObserver</span>(</span><br><span class="line">    target,</span><br><span class="line">    <span class="function">(<span class="params">[&#123;</span></span></span><br><span class="line"><span class="params"><span class="function">      isIntersecting</span></span></span><br><span class="line"><span class="params"><span class="function">    &#125;], observerElement</span>) =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">if</span> (isIntersecting) &#123;</span><br><span class="line">        <span class="title function_">stop</span>()</span><br><span class="line">        <span class="comment">// 调用API获取数据</span></span><br><span class="line">        <span class="title function_">apiFn</span>().<span class="title function_">then</span>(<span class="function"><span class="params">data</span> =&gt;</span> &#123;</span><br><span class="line">          result.<span class="property">value</span> = data.<span class="property">result</span></span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  )</span><br><span class="line">  <span class="comment">// 返回---&gt;数据（dom,后台数据）</span></span><br><span class="line">  <span class="keyword">return</span> &#123;</span><br><span class="line">    result,</span><br><span class="line">    target</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>如何使用</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">HomePanel</span> <span class="attr">title</span>=<span class="string">&quot;人气推荐&quot;</span> <span class="attr">sub-title</span>=<span class="string">&quot;人气爆款 不容错过&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;<span class="name">ul</span> <span class="attr">ref</span>=<span class="string">&quot;target&quot;</span> <span class="attr">class</span>=<span class="string">&quot;goods-list&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">li</span> <span class="attr">v-for</span>=<span class="string">&quot;item in objList&quot;</span> <span class="attr">:key</span>=<span class="string">&quot;item.id&quot;</span>&gt;</span> &#123;&#123; item &#125;&#125; <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">     <span class="comment">&lt;!--  给要渲染数据的父元素绑定  ref=&quot;target&quot;  内容区域 渲染数据   --&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">  <span class="tag">&lt;/<span class="name">HomePanel</span>&gt;</span></span></span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">import</span> &#123; ref &#125; <span class="keyword">from</span> <span class="string">&quot;vue&quot;</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">import</span> <span class="title class_">HomePanel</span> <span class="keyword">from</span> <span class="string">&quot;@/components/home/homePanel&quot;</span>;  <span class="comment">// 组件</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">import</span> &#123; moodsList &#125; <span class="keyword">from</span> <span class="string">&quot;@/api&quot;</span>;   <span class="comment">// 引入封装好的 api</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">import</span> &#123; useLazyData &#125; <span class="keyword">from</span> <span class="string">&quot;@/hooks&quot;</span>;   <span class="comment">// 引入数据懒加载</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  <span class="attr">name</span>: <span class="string">&quot;HomeNew&quot;</span>,</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  <span class="attr">components</span>: &#123; <span class="title class_">HomePanel</span> &#125;,</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  <span class="title function_">setup</span>(<span class="params"></span>) &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="comment">// let objList = ref([]); // 热门品牌数据</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="comment">// moodsList().then((res) =&gt; &#123; // 之前这么引入数据</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="comment">//   objList.value = res.result;</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="comment">// &#125;);</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="comment">// 懒加载 引入数据    target是dom元素    result 是返回的数据   把他 return 出去  objList: result, </span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="keyword">let</span> &#123; target, result &#125; = <span class="title function_">useLazyData</span>(moodsList);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    <span class="keyword">return</span> &#123; <span class="attr">objList</span>: result, target &#125;;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  &#125;,</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">&#125;;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br></pre></td></tr></table></figure>

<h3 id="复杂判断简化"><a href="#复杂判断简化" class="headerlink" title="复杂判断简化"></a>复杂判断简化</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">const btnValue = (value) =&gt; &#123;</span><br><span class="line">     const actions = [&quot;付款&quot;, &quot;发货&quot;, &quot;收货&quot;, &quot;再来一单&quot;];</span><br><span class="line">     return actions[value];</span><br><span class="line"></span><br><span class="line">     // console.log(arr);</span><br><span class="line">     // if (value == 0) &#123;</span><br><span class="line">     //   return &quot;付款&quot;;</span><br><span class="line">     // &#125; else if (value == 1) &#123;</span><br><span class="line">     //   return &quot;发货&quot;;</span><br><span class="line">     // &#125; else if (value == 2) &#123;</span><br><span class="line">     //   return &quot;收货&quot;;</span><br><span class="line">     // &#125; else if (value == 3) &#123;</span><br><span class="line">     //   return &quot;再来一单&quot;;</span><br><span class="line">     // &#125;</span><br><span class="line"></span><br><span class="line">     // switch (value) &#123;</span><br><span class="line">     //   case 0:</span><br><span class="line">     //     return &quot;付款&quot;;</span><br><span class="line">     //     break;</span><br><span class="line">     //   case 1:</span><br><span class="line">     //     return &quot;发货&quot;;</span><br><span class="line">     //     break;</span><br><span class="line">     //   case 2:</span><br><span class="line">     //     return &quot;收货&quot;;</span><br><span class="line">     //     break;</span><br><span class="line">     //   case 3:</span><br><span class="line">     //     return &quot;再来一单&quot;;</span><br><span class="line">     //     break;</span><br><span class="line">     //   default:</span><br><span class="line">     // &#125;</span><br><span class="line">     </span><br><span class="line">   &#125;;</span><br></pre></td></tr></table></figure>

<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io">孙志豪</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/">https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/%E5%A4%A9%E7%A9%BA.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/"><img class="prev-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">JS数组方法</div></div></a></div><div class="next-post pull-right"><a href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E6%97%B6%E9%97%B4%E8%BF%87%E6%BB%A4/"><img class="next-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">时间过滤</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">孙志豪</div><div class="author-info__description">吾日三省吾身：为人谋而不忠乎？与朋友交而不信乎？传不习乎？</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/szhihao/szhihao"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/szhihao/szhihao" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/qq_54753561" target="_blank" title="CSDN"><i class="fa fa-book-open"></i></a><a class="social-icon" href="mailto:zhihaomail@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0"><span class="toc-number">1.</span> <span class="toc-text">开发封装函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E9%A1%B9%E7%9B%AE%E5%B0%81%E8%A3%85axios"><span class="toc-number">1.0.1.</span> <span class="toc-text">创建项目封装axios</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%AD%E9%97%B4%E5%AD%97%E7%AC%A6%E5%8F%98%E6%88%90-%E6%98%9F%E5%8F%B7"><span class="toc-number">1.0.2.</span> <span class="toc-text">中间字符变成 星号</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#reduce-%E8%BF%87%E6%BB%A4%E8%BD%AC%E6%8D%A2%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.0.3.</span> <span class="toc-text">reduce 过滤转换格式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B4%AD%E7%89%A9%E8%BD%A6%E7%9A%84%E7%AE%97%E6%B3%95%E9%80%BB%E8%BE%91"><span class="toc-number">1.0.4.</span> <span class="toc-text">购物车的算法逻辑</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%95%86%E5%93%81%E5%8D%A1%E7%89%87%E5%8A%A0%E5%85%A5%E8%B4%AD%E7%89%A9%E8%BD%A6%E5%88%A4%E6%96%AD%E9%87%8D%E5%A4%8D"><span class="toc-number">1.0.5.</span> <span class="toc-text">商品卡片加入购物车判断重复</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%A8%E9%80%89%E5%8F%8D%E9%80%89"><span class="toc-number">1.0.6.</span> <span class="toc-text">全选反选</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%95%86%E5%93%81%E9%80%89%E8%A7%84%E6%A0%BC%E6%A0%B7%E5%BC%8F%E7%9A%84%E9%80%BB%E8%BE%91"><span class="toc-number">1.0.7.</span> <span class="toc-text">商品选规格样式的逻辑</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%9A%84%E4%B8%80%E4%B8%AA%E6%87%92%E5%8A%A0%E8%BD%BD"><span class="toc-number">1.0.8.</span> <span class="toc-text">数据的一个懒加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E6%9D%82%E5%88%A4%E6%96%AD%E7%AE%80%E5%8C%96"><span class="toc-number">1.0.9.</span> <span class="toc-text">复杂判断简化</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="性能优化面试题"/></a><div class="content"><a class="title" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题">性能优化面试题</a><time datetime="2022-10-12T12:01:36.000Z" title="Created 2022-10-12 20:01:36">2022-10-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS字符串方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法">JS字符串方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS对象方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法">JS对象方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS数组方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法">JS数组方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="开发封装函数"/></a><div class="content"><a class="title" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数">开发封装函数</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 孙志豪</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">Search</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  Loading the Database</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="Search for Posts" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>